from datetime import timedelta
from datetime import datetime

# 需要执行简单的时间转换,比如天到秒,小时到分钟等的转换
# 如果处理更加复杂的日期操作,比如处理时区,模糊时间范围,节假日计算等等,考虑使用dateutil模块(python-dateutil)
def demo_1():
    a = timedelta(days=2, hours=6)
    b = timedelta(hours=4.5)
    c = a + b
    print(c.days)
    print(c.seconds)

# 表示指定的日期和时间
def demo_2():
    a = datetime(2012, 9, 23)
    print(a + timedelta(days=10))
    b = datetime(2012, 12, 21)
    d = b - a
    print(d.days)
    now = datetime.today()
    print(now)
    print(now + timedelta(minutes=10))

# datetime会自动处理闰年
def demo_3():
    a = datetime(2012, 3, 1)
    b = datetime(2012, 2, 28)
    print((a - b).days)
    c = datetime(2013, 3, 1)
    d = datetime(2013, 2, 28)
    print((c - d).days)


if __name__ == '__main__':
    # demo_1()
    # demo_2()
    demo_3()